package com.sun.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sun.entity.Category;
import com.sun.entity.Store;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Project: hospitalDrugInformationManagement
 * @Author: 86178
 * @Date: 2023/3/21 15:17
 * @FileName: StoreMapper
 * @Description: ""
 */
@Mapper
public interface StoreMapper extends BaseMapper<Store> {

    @Select("select SUM(drug_number) from store")
    public int countStore();

    @Select("select name,sum(drug_number) AS categoryNum FROM category c left JOIN drug ON drug.category_id = c.category_id LEFT JOIN store ON store.drug_id = drug.drug_id GROUP BY c.`name`")
    public List<Category> countByCategory();
}
